package com.kfm.base.function;

import java.util.Arrays;

public class Demo09 {

    public static void main(String[] args) {

        int[] arr = {4, 2, 1, 4, 3, 6};

        insertionSort(arr);

        System.out.println(Arrays.toString(arr));
    }

    public static void insertionSort(int[] arr){
        for (int i = 1; i < arr.length; i++) {
            int current = arr[i];
            int preIndex = i - 1;
            while (preIndex >= 0 && arr[preIndex] > current){
                arr[preIndex + 1] = arr[preIndex];
                preIndex --;
            }

            arr[preIndex + 1] = current;
        }

    }
}
